﻿using Engine;
using Engine.Graphics;
using Engine.Media;
using Game;
using GameEntitySystem;
using TemplatesDatabase;

public class 血显 : Component, IDrawable
{
  
    public int[] DrawOrders
    {
        get
        {
            return 血显.m_drawOrders;
        }
    }

    
    public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
    {
        this.subsystemModelsRenderer = base.Project.FindSubsystem<SubsystemModelsRenderer>(true);
        this.componentCreature = base.Entity.FindComponent<ComponentCreature>(true);
        this.componentHealth = base.Entity.FindComponent<ComponentHealth>(true);
        this.displayName = this.componentCreature.DisplayName;
        this.height = this.componentCreature.ComponentBody.BoxSize.Y;
    }

  
    public void Draw(Camera camera, int drawOrder)
    {
        Vector3 vector = Vector3.Transform(this.componentCreature.ComponentBody.Position + 1.02f * Vector3.UnitY * this.height + new Vector3(0f, 0.3f, 0f), camera.ViewMatrix);
        Vector3 vector2 = Vector3.TransformNormal(0.005f * Vector3.Normalize(Vector3.Cross(camera.ViewDirection, camera.ViewUp)), camera.ViewMatrix);
        Vector3 vector3 = Vector3.TransformNormal(-0.005f * Vector3.UnitY, camera.ViewMatrix);
        ComponentChaseBehavior componentChaseBehavior = this.componentCreature.ComponentBody.Entity.FindComponent<ComponentChaseBehavior>();
        string text = string.Format(this.displayName + "\nHP:{0:0.00}", this.componentCreature.ComponentHealth.Health * this.componentCreature.ComponentHealth.AttackResilience);
        if (vector.Z <= 0f)
        {
            Color color = Color.Lerp((componentChaseBehavior == null) ? Color.LightGreen : ((componentChaseBehavior.m_target == null && (double)this.componentHealth.Health >= 0.1) ? Color.White : (((double)this.componentHealth.Health >= 0.1) ? Color.Red : Color.LightYellow)), Color.Transparent, MathUtils.Saturate((vector.Length() - 4f) / 3f));
            if (color.A > 8)
            {
                BitmapFont bitmapFont = ContentManager.Get<BitmapFont>("Fonts/Pericles");
                this.subsystemModelsRenderer.PrimitivesRenderer.FontBatch(bitmapFont, 1, DepthStencilState.DepthRead, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.LinearClamp).QueueText(text, vector, vector2, vector3, color, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter);
            }
        }
    }
    public SubsystemModelsRenderer subsystemModelsRenderer;
    public ComponentCreature componentCreature;
    public ComponentHealth componentHealth;
    public static int[] m_drawOrders = new int[1];
    public string displayName;
    public float height;
    public ComponentChaseBehavior componentChaseBehavior;
}